<template>
  <div>
    <panel-group />
    <el-row :gutter="20">
      <el-col :span="24">
        <div class="chart__wrap">
          <echart :options="barEchatOptions" :height="'300px'" />
        </div>
      </el-col>
    </el-row>
    <div class="chart__wrap">
      <echart :options="lineEchatOptions" :height="'300px'" />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive } from 'vue'
import Echart from '_c/Echart/index.vue'
import PanelGroup from './components/PanelGroup.vue'
import { lineOptions, barOptions } from './echart-data'
import type { EChartOption } from 'echarts'
import { getIndexApi, getDailyReportListApi, getTeacherInfoApi } from '@/views/dashboard/api'
export default defineComponent({
  name: 'Dashboard',
  components: {
    Echart,
    PanelGroup
  },
  setup() {
    const lineEchatOptions = reactive<EChartOption>(lineOptions)
    const barEchatOptions = reactive<EChartOption>(barOptions)

    async function getDailyReportList() {
      try {
        const res = await getDailyReportListApi()
        console.info('res:', res)
        if (res.code === 0) {
          // 收益y轴数据
          if (lineEchatOptions.series !== undefined) {
            lineEchatOptions.series[0].data = res.data.sameMonthIncomeMoney
            lineEchatOptions.series[1].data = res.data.lastMonthIncomeMoney
          }

          // 订单y轴数据
          if (barEchatOptions.series !== undefined) {
            barEchatOptions.series[0].data = res.data.sameMonthOrderNum
            barEchatOptions.series[1].data = res.data.lastMonthOrderNum
          }
        }

        // 收益x轴数据
        for (const key in lineEchatOptions.xAxis) {
          if (key === 'data') {
            lineEchatOptions.xAxis[key] = res.data.sameMonthDaysNos
          }
        }

        // 订单x轴数据
        for (const key in barEchatOptions.xAxis) {
          if (key === 'data') {
            barEchatOptions.xAxis[key] = res.data.sameMonthDaysNos
          }
        }
      } catch (e) {
        console.log(e)
      }
    }
    getDailyReportList()

    return {
      lineEchatOptions,
      barEchatOptions

    }
  }
})
</script>

<style lang="less" scoped>
.chart__wrap {
  margin-bottom: 20px;
  border-radius: 5px;
  background-color: @contentBg;
  padding: 10px;
}
</style>
